#include "SFMLSprite.h"
#include "..\ScaleFactor.h"

using namespace vn;

SFMLSprite::SFMLSprite(float p_layer) : SFMLDrawable(p_layer)
{
	m_sprite.setScale(SCALEF, SCALEF);
}

SFMLSprite::~SFMLSprite(void){}

void SFMLSprite::draw(sf::RenderWindow& p_renderWindow)
{
	p_renderWindow.draw(m_sprite);
}

void SFMLSprite::draw(sf::RenderTexture& p_renderTexture)
{
	p_renderTexture.draw(m_sprite);
}

void SFMLSprite::setTexture(const sf::Texture& p_texture)
{
	m_sprite.setTexture(p_texture);
}

void SFMLSprite::setTextureRect(int x, int y, int w, int h)
{
	m_sprite.setTextureRect(sf::IntRect(x, y, w, h));
}

void SFMLSprite::setTextureRect(const vn::IntRect& p_textureRect)
{
	m_sprite.setTextureRect(sf::IntRect(p_textureRect.x, p_textureRect.y, p_textureRect.w, p_textureRect.h));
}

void SFMLSprite::setAngle(float p_angle)
{
	m_sprite.setRotation(p_angle);
}

void SFMLSprite::setScale(const vn::Scale& p_scale)
{
	m_sprite.setScale(p_scale.x * SCALEF, p_scale.y * SCALEF);
}

void SFMLSprite::setScale(float x, float y)
{
	m_sprite.setScale(x * SCALEF, y * SCALEF);
}

void SFMLSprite::setPosition(const vn::Vector2& p_position)
{
	m_sprite.setPosition(p_position.x * SCALEF, p_position.y * SCALEF);
}

void SFMLSprite::setPosition(float x, float y)
{
	m_sprite.setPosition(x * SCALEF, y * SCALEF);
}

void SFMLSprite::translate(const vn::Vector2& p_velocity)
{
	m_sprite.setPosition(m_sprite.getPosition().x + (p_velocity.x * SCALEF), m_sprite.getPosition().y + (p_velocity.y * SCALEF));
}

void SFMLSprite::translate(float x, float y)
{
	m_sprite.setPosition(m_sprite.getPosition().x + (x * SCALEF), m_sprite.getPosition().y + (y * SCALEF));
}

void SFMLSprite::setOrigin(float x, float y)
{
	m_sprite.setOrigin(x, y);
}

void SFMLSprite::setOrigin(const vn::Vector2& p_origin)
{
	m_sprite.setOrigin(sf::Vector2f(p_origin.x, p_origin.y));
}

void SFMLSprite::setColor(const vn::Color& p_color)
{
	m_sprite.setColor(sf::Color(p_color.r, p_color.g, p_color.b, p_color.a));
}

const vn::Vector2 SFMLSprite::getPosition() const
{
	return vn::Vector2(m_sprite.getPosition().x / SCALEF, m_sprite.getPosition().y / SCALEF);
}

const vn::Scale SFMLSprite::getScale() const
{
	return vn::Scale(m_sprite.getScale().x / SCALEF, m_sprite.getScale().y / SCALEF);
}

const float SFMLSprite::getAngle() const
{
	return m_sprite.getRotation();
}

const vn::IntRect SFMLSprite::getTextureRect() const
{
	return vn::IntRect(m_sprite.getTextureRect().left, m_sprite.getTextureRect().top, m_sprite.getTextureRect().width, m_sprite.getTextureRect().height);
}

const vn::Vector2 SFMLSprite::getOrigin() const
{
	return vn::Vector2(m_sprite.getOrigin().x, m_sprite.getOrigin().y);
}

const vn::Color SFMLSprite::getColor() const
{
	return vn::Color(m_sprite.getColor().r, m_sprite.getColor().g, m_sprite.getColor().b, m_sprite.getColor().a);
}

void SFMLSprite::setDoRender(bool p_value)
{
	m_render = p_value;
}